package com.googlecode.sparda.commons.swing;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.TableModel;

/**
 * A {@link ColumnNameToMethodCollection} composed by {@link ColumnNameToMethod}.
 * 
 * @author Fabio Grucci (<i>alias</i> <b>Phoenix</b>)
 *
 * @param <E> The element Type managed in the {@link TableModel}
 */
public class ColumnNameToMethodCollection<E> {
	/**
	 * The {@link List} of {@link ColumnNameToMethod}.
	 */
	private final List<ColumnNameToMethod<E>> columnNameToMethods;
	/**
	 * Create a nex {@link ColumnNameToMethodCollection}.
	 */
	public ColumnNameToMethodCollection() {
		this.columnNameToMethods = new ArrayList<ColumnNameToMethod<E>>();
	}
	/**
	 * Method that return the column name managed by the collection.
	 * @return The column names array
	 */
	public String[] getColumnNames() {
		final String[] columnNames = new String[columnNameToMethods.size()];
		for (int i = 0; i < columnNames.length; i++)
			columnNames[i] = this.columnNameToMethods.get(i).getColumnName();
		return columnNames;
	}
	/**
	 * Method that return the {@link ColumnNameToMethod} corresponding.
	 * @param index The index
	 * @return The corresponding {@link ColumnNameToMethod}
	 */
	public ColumnNameToMethod<E> getColumnNameToMethod(int index) {
		return this.columnNameToMethods.get(index);
	}
	/**
	 * Method to add a {@link ColumnNameToMethod} to the collection.
	 * @param columnNameToMethod The {@link ColumnNameToMethod} to add
	 * @return <code>true</code> if this collection changed as a result of the call
	 */
	public boolean addColumnNameToMethod(ColumnNameToMethod<E> columnNameToMethod) {
		return this.columnNameToMethods.add(columnNameToMethod);
	}
	/**
	 * Method that return the size of the {@link ColumnNameToMethodCollection}.
	 * @return The size of the collection
	 */
	public int size() {
		return this.columnNameToMethods.size();
	}
	/**
	 * Method that return the column name in the index.
	 * @param index The index
	 * @return The corresponding column name
	 */
	public String getColumnName(int index) {
		return this.getColumnNameToMethod(index).getColumnName();
	}
	
}
